<!DOCTYPE html>
<html lang="en">
<title>团体课程</title>
<#import "/layout/layout.html" as body/>
<@body.page>

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title overflow">
                    <h5 class="pull-left">团体课程列表</h5>
                    <a href="to_course_team_add" class="btn btn-sm btn-primary pull-right">添加新团体</a>
                </div>
                <div class="ibox-content">
                    <div class="table-responsive">
                        <form class="form-inline" role="form" action="to_course_team_query" method="post" id="course_select_form">
                            <div class="form-group date-rangepicker">
                                <label for="daterange">日期：</label>
                                <input class="form-control" id="daterange" type="text" name="daterange"
                                <#if daterange??>value="${daterange!}"</#if>
                                style="width: 280px"/>
                            </div>
                            <div class="form-group">
                                <label for="courseId">课程ID：</label>
                                <input class="form-control" type="number" min="1" id="courseId" name="courseId"
                                <#if courseId??&&courseId gt 0>value="${courseId!}"</#if>
                                />
                            </div>
                            
                            <div class="form-group margin-left">
                                <label for="isVipUsed">会员专属</label>
                                <select class="form-control" id="isVipUsed" name="isVipUsed">
                                    <option value="-1"
                                    <#if isVipUsed??&&isVipUsed == "-1">selected="true"</#if>
                                    >全部</option>
	                                <option value="1"
	                                 <#if isVipUsed??&&isVipUsed == "1">selected="true"</#if>
	                                >是</option>
	                                <option value="0"
	                                 <#if isVipUsed??&&isVipUsed == "0">selected="true"</#if>
	                                >否</option>
                                </select>
                            </div>
                            
                            <div class="form-group margin-left">
                                <label for="coachId">教练：</label>
                                <select class="form-control" id="coachId" name="coachId">
                                    <option value="-1">全部</option>
                                    <#if coachList??>
                                        <#list coachList as coach>
                                            <option value="${coach.id!}"
                                            <#if coachId?default(0)==coach.id > selected="selected"</#if>
                                            >${coach.nickName!}</option>
                                        </#list>
                                    </#if>
                                </select>
                            </div>
                            <div class="form-group margin-left">
                                <label for="storeId">门店：</label>
                                <select class="form-control" id="storeId" name="storeId">
                                    <option value="-1">全部</option>
                                    <#if storeList??>
                                        <#list storeList as store>
                                            <option value="${store.id!}"
                                            <#if storeId?default(0)==store.id > selected="selected"</#if>
                                            >${store.storeName!}</option>
                                        </#list>
                                    </#if>
                                </select>
                            </div>
                            <div class="form-group margin-left">
                                <label>状态：</label>
                                <select class="form-control" id="status" name="status">
                                    <option value="0"
                                    <#if status?default("")=="0" > selected="selected"</#if>
                                    >全部</option>
                                    <option value="1"
                                    <#if status?default("")=="1" > selected="selected"</#if>
                                    >系统录入</option>
                                    <option value="2"
                                    <#if status?default("")=="2" > selected="selected"</#if>
                                    >已上线</option>
                                    <option value="3"
                                    <#if status?default("")=="3" > selected="selected"</#if>
                                    >已下线</option>
                                    <option value="4"
                                    <#if status?default("")=="4" > selected="selected"</#if>
                                    >已删除</option>
                                    <option value="5"
                                    <#if status?default("")=="5" > selected="selected"</#if>
                                    >已结束</option>
                                </select>
                            </div>
                            <!-- submit -->
                            <button type="submit" class="btn btn-outline btn-primary" id="btn_select" style="margin-top: 5px">确认
                            </button>
                            <input type="hidden" value="${pageNow!}" id="page" name="page">
                        </form>
                        <table class="table table-hover table-center dataTables-example">
                            <thead>
                            <tr>
                                <th>序号</th>
                                <th>课程ID</th>
                                <th>课程名称</th>
                                <th>教练</th>
                                <th>费用</th>
                                <th>会员价格</th>
                                <th>开课</th>
                                <th>时长(分钟)</th>
                                <th>门店(操房)</th>
                                <th>上限</th>
                                <th>已报</th>
                                <th>排队</th>
                                <th>状态</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <!--  -->
                            <#if courseList??>
                                <#list courseList as course>
                                    <tr>
                                        <td>${course_index+1}</td>
                                        <td>${course.courseId!}</td>
                                        <td>${course.title!}</td>
                                        <td>${course.coachName!}</td>
                                        <td>${course.primePrice!}</td>
                                        <td>${course.price!}</td>
                                        <td>${course.startTime!}</td>
                                        <td>${course.duration!}</td>
                                        <td>${course.storeName!} <br>( ${(course.workoutRoomName)!"无"} )</td>
                                        <td>${course.maxCount!}</td>
                                        <td>${course.currentCount!}</td>
                                        <td>${course.waitCount!}</td>
                                        <td>${course.status!}</td>
                                        <td>
                                            <!-- <button type="button" class="btn btn-default" id="course_look_over" onclick="location.href='${baseUrl}system/course/to_course_team_edit?courseId=${course.courseId!}&detail=detail'"><i class="fa fa-eye"></i> 查看
                                            </button> -->
                                            <#if course.status ="售卖中">
                                                <button type="button" class="btn btn-default" onclick="closeCourse(${course.courseId!})"><i class="fa fa-arrow-circle-down"></i>下架
                                            </#if>
                                            </button>
                                            <#if course.status ="已删除">
                                                <#else>
                                                <!-- 
                                                    <button type="button" class="btn btn-default" onclick="location.href='${baseUrl}system/course/to_course_team_edit?courseId=${course.courseId!}'"><i class="fa fa-pencil"></i> 编辑
                                                     -->
                                                 <button type="button" class="btn btn-default" onclick="editCourse(${course.courseId!})"><i class="fa fa-pencil"></i> 编辑
                                            </#if>

                                            </button>
                                        </td>
                                    </tr>
                                </#list>
                            </#if>
                            <!--  -->
                            </tbody>
                        </table>
                    </div>
                </div>
                <div class="ibox-footer overflow">
                    <h4 class="pull-left">合计：#{pageCount}个课程 </h4>

                    <div id="copot-page" class="pull-right"></div>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="${baseUrl}js/main.js"></script>

<script>

    //跳转编辑
    function editCourse(id) {
    	debugger;
    	var daterange = $("#daterange").val();
    	var courseId = $("#courseId").val();
    	var isVipUsed = $("#isVipUsed").val();
    	var conditionCoachId = $("#coachId").val();
    	var storeId = $("#storeId").val();
    	var status = $("#status").val();
    	var page = $("#page").val();
    	var url =  "to_course_team_edit?courseId=" + id +"&conditionDaterange="+daterange+"&conditionCourseId="+courseId+"&conditionIsVipUsed="+isVipUsed+"&conditionCoachId="+conditionCoachId
		+"&conditionStoreId="+storeId+"&conditionStatus="+status+"&conditionPage="+page;
        window.location = url;
    }

    //下架
    function closeCourse(id) {
        debugger
        swal({
            title: "确定要下架吗?",
            text: "点击下架后该檬营课程将立即变为下架状态!",
            type: "warning",
            showCancelButton: true,
            cancelButtonText: "容我三思！",
            confirmButtonText: "下架!"
        }).then(function () {
            $.ajax({
                type: "post",
                url: "course_close",
                data: {"id": id},
                success: function (result) {
                    if (result) {
                        swal("下架成功!", "页面即将重新加载,请稍后...", "success");
                        window.setTimeout(function () {
                            window.location.reload()
                        }, 1000);
                    }
                }
            });
        });
    }

    //删除
    function deleteCourse(courseId) {

        swal({
            title: "确定要删除吗?",
            text: "删除后不可恢复!",
            type: "warning",
            showCancelButton: true,
            cancelButtonText: "容我三思！",
            confirmButtonText: "删除!"
        }).then(function () {
            $.ajax({
                type: "post",
                url: "course_delete",
                data: {"id": courseId},
                success: function (result) {
                    if (result) {
                        swal("删除成功!", "页面即将重新加载,请稍后...", "success");
                        window.setTimeout(function () {
                            window.location.reload()
                        }, 1000);
                    }
                }
            });
        });
    }

    $(document).ready(function () {
    	
    	
        //时间选择
        //时间选择
        $('input[name="daterange"]').daterangepicker({
            startDate: moment().startOf('day'),
            endDate: moment(),
            //minDate: '01/01/2012',    //最小时间
            //maxDate: moment(), //最大时间
            dateLimit: {days: 365}, //起止时间的最大间隔
            showDropdowns: true,
            showWeekNumbers: false, //是否显示第几周
            timePicker: false, //是否显示小时和分钟
            timePickerIncrement: 60, //时间的增量，单位为分钟
            timePicker12Hour: false, //是否使用12小时制来显示时间
            ranges: {
                //'最近1小时': [moment().subtract('hours',1), moment()],
                '今日': [moment().startOf('day'), moment()],
                '昨日': [moment().subtract('days', 1).startOf('day'), moment().subtract('days', 1).endOf('day')],
                '最近7日': [moment().subtract('days', 6), moment()],
                '最近30日': [moment().subtract('days', 30), moment()]
            },
            opens: 'right', //日期选择框的弹出位置
            buttonClasses: ['btn btn-default'],
            applyClass: 'btn-small btn-primary blue',
            cancelClass: 'btn-small',
            format: 'YYYY-MM-DD', //控件中from和to 显示的日期格式 YYYY-MM-DD HH:mm:ss
            separator: '~',
            locale: {
                applyLabel: '确定',
                cancelLabel: '取消',
                fromLabel: '起始时间',
                toLabel: '结束时间',
                customRangeLabel: '自定义',
                daysOfWeek: ['日', '一', '二', '三', '四', '五', '六'],
                monthNames: ['一月', '二月', '三月', '四月', '五月', '六月',
                    '七月', '八月', '九月', '十月', '十一月', '十二月'],
                firstDay: 1
            }
        }, function (start, end, label) {//格式化日期显示框
            $('.date-rangepicker span').html(start.format('YYYY-MM-DD HH:mm:ss') + ' - ' + end.format('YYYY-MM-DD HH:mm:ss'));
        });
        //分页
        new Page({
            parent: $("#copot-page"),
            nowPage: (#{pageNow!} == 0 ? 1 :#{pageNow!}),
            pageSize:10,
            totalCount: #{pageCount},
        	setting: {
            defaultPage: 7,//默认显示可点击分页的个数
            firstPageText: "首页",
            prevPageText:"上一页",
            nextPageText:"下一页",
            lastPageText:"尾页"},
        callback: function (nowPage, totalPage) {
            $("#page").val(nowPage);
            $("#course_select_form").submit();
        }
    	})
        ;
        $("#btn_select").click(function () {
        });
        
        
        
    });
    function delCourse(id) {
        $.ajax({
            url: "to_course_team_delete",//
            data: {
                "courseId": id
            },
            type: 'post',
            cache: false,
            dataType: 'json',
            success: function (data) {
                if (data.tet == 1) {
                    window.location.reload();
                } else {
                    swal(data.data, "如有问题请联系管理员处理", "error");
                    return;
                }

            },
            error: function () {
                swal("删除失败", "请联系管理员处理", "error");
                return;
            }
        });
    }
</script>

</@body.page>
</html>